<%@ page language="java" pageEncoding="utf8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US" dir="ltr">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<link rel="stylesheet" href="<c:url value="/css/shopadmin.css"/>" type="text/css" />
		<link rel="stylesheet" href="<c:url value='/scripts/themes/base/jquery.ui.all.css'/>" type="text/css" />
	</head>
	<body style="">
		<div id="headBar" class="head_content"></div>
		<div id="main" class="main_content">
			<form action="mt_coupon_save.html" method="post" id="coupon_form">
				<input type="hidden" name="marketCoupons.couponId" value="${marketCoupons.couponId}" />
				<div class="tableform">

					<div class="division">
						<table width="100%" cellspacing="0" cellpadding="0" border="0">
							<tbody>
								<tr>
									<th>
										名称:
									</th>
									<td>
										<input  name="marketCoupons.couponName" class="x-input " value="${marketCoupons.couponName}"/>
									</td>
								</tr>
							</tbody>
						</table>
					</div>
					<div class="division">
						<table width="100%" cellspacing="0" cellpadding="0" border="0">
							<tbody>
								<tr>
									<th>
										优惠券前缀:
									</th>
									<td>
									
										<input <c:if test="${not empty marketCoupons.couponId}">disabled="disabled" </c:if> value="${marketCoupons.couponPrefix }"  name="marketCoupons.couponPrefix" class="x-input " />
										设置后无法更改
									</td>
								</tr>
								<tr>
									<th>
										状态:
									</th>
									<td>
										<select name="marketCoupons.couponStatus" id="coupon_status" style="width: 80px;">
											<option value="1">
												启用
											</option>
											<option value="0">
												禁用
											</option>
										</select>
									</td>
								</tr>
							</tbody>
						</table>
					</div>

					<div class="division">
						<table cellspacing="0" cellpadding="0" border="0">
							<tbody>
								<c:forEach var="marketPromotionScheme" items="${marketPromotionSchemes}" varStatus="index">
									<tr>
										<th style="width: 10px;">
											<input id="coupon_scheme_${marketPromotionScheme.pmtsId}" type="radio" method="${marketPromotionScheme.pmtsMethod}" onclick="setCouponPromotion(${marketPromotionScheme.pmtsId})"
												<c:if test="${index.index == 0 }">checked="checked"</c:if> value="${marketPromotionScheme.pmtsId}" name="marketPromotion.pmtsId" />
										</th>
										<td>
											<label>
												优惠券规则--${marketPromotionScheme.pmtsName }
											</label>
										</td>
									</tr>
								</c:forEach>
							</tbody>
						</table>
					</div>

				</div>

				<div class="tableform">
					<h4>
						优惠方式
					</h4>
					<div class="division">
						<table>
							<tbody>
								<tr id="promotion_from_to">
									<th>
										订单优惠条件：
									</th>
									<td>
										<input id="marketPromotion_orderMoneyFrom" size="10" value="${marketPromotion.orderMoneyFrom}" name="marketPromotion.orderMoneyFrom" class="x-input ">
											<b>≤</b>订单金额 ＜ <c:if test="${not empty marketPromotion.orderMoneyTo}">
												<input type="text" name="marketPromotion.orderMoneyTo" value="${marketPromotion.orderMoneyTo}" size="10" class="x-input ">
											</c:if>
											<c:if test="${empty marketPromotion.orderMoneyTo}">
												<input type="text" name="marketPromotion.orderMoneyTo" value="999999" size="10" class="x-input ">
											</c:if>
									</td>
								</tr>
								<tr>
									<th>
										允许参加会员等级：
									</th>
									<td id="promotion_level">
										<c:forEach var="level" items="${marketPromotionMemberLevels}" varStatus="index">
											<input type="hidden" name="marketPromotionMemberLevels[${index.index }].pmlId" value="${level.pmlId}" />
											<input type="checkbox" value="${level.memberLvId}" vname="promotion_level" <c:if test="${not empty level.pmlId }">checked="checked"</c:if>
												name="marketPromotionMemberLevels[${index.index }].memberLvId" />
										 ${level.levelName}
										</c:forEach>

									</td>
								</tr>
							</tbody>
						</table>
					</div>
				</div>
				<div class="tableform">
					<h4>
						优惠券使用时间
					</h4>
					<div class="division">
						<table width="100%" cellspacing="0" cellpadding="0" border="0">
							<tbody>

								<tr>
									<th>
										开始时间:
									</th>
									<td>

										<input size="10" id="rule_start_time" name="marketPromotion.pmtTimeBeginString" value="${marketPromotion.pmtTimeBeginString}" class="cal cal" type="text">
									</td>
								</tr>
								<tr>
									<th>
										结束时间:
									</th>
									<td>

										<input size="10" id="rule_end_time" name="marketPromotion.pmtTimeEndString" value="${marketPromotion.pmtTimeEndString}" class="cal cal" type="text">
									</td>
								</tr>
							</tbody>
						</table>
					</div>
				</div>
				<div class="tableform">
					<h4>
						优惠内容
					</h4>
					<input type="hidden" name="marketPromotion.pmtIfcoupon" value="false" />
					<input type="hidden" name="marketPromotion.pmtId" value="${marketPromotion.pmtId}">
						<input type="hidden" name="marketPromotion.pmtBasicType" value="order" />
						<input type="hidden" name="marketPromotion.relatedType" value="coupon" />
						<input type="hidden" name="marketPromotion.pmtMethod" value="coupon_discount" id="coupon_scheme_method" />
						<input type="hidden" name="marketPromotion.pmtBondType" value="2" />

						<div style="float: left;" class="division">
							<h5 id="coupon_promotion_title">
								请输入给予多少折扣
							</h5>
							<input type="text" name="marketPromotion.pmtMethodValue" id="coupon_scheme_method_value" value="${marketPromotion.pmtMethodValue}" class="x-input " />
							<span id="method_description">如果打9折，请输入0.9； </span>

						</div>
						<hr class="clear" />
				</div>
				<div class="tableform">
					<h4>
						规则描述
					</h4>
					<textarea required="true" rows="6" cols="60" name="marketPromotion.pmtDescribe">${marketPromotion.pmtDescribe }</textarea>
					<br>
						<span class="fontcolorGray">此描述会显示在前台相关页面展示给顾客 </span>
				</div>
				<div class="table-action">
					<button class="btn" type="submit">
						<span><span>下一步</span> </span>
					</button>
					&nbsp;&nbsp;
					<a href="mt_coupon_list.html">取消</a>
				</div>
			</form>
		</div>
		<div id="footBar" class="foot_content"></div>




		<script type="text/javascript" src="<c:url value='/scripts/jquery-1.4.2.js'/>"></script>
		<script type="text/javascript" src="<c:url value='/scripts/jquery.validate.js'/>"></script>
		<script type="text/javascript" src="<c:url value='/scripts/ui/jquery.ui.core.js'/>"></script>
		<script type="text/javascript" src="<c:url value='/scripts/ui/jquery.ui.widget.js'/>"></script>
		<script type="text/javascript" src="<c:url value='/scripts/ui/jquery.ui.datepicker.js'/>"></script>
		<script type="text/javascript" src="<c:url value='/scripts/ui/i18n/jquery.ui.datepicker-zh-CN.js'/>"></script>
		<script type="text/javascript">
		
		<c:if test="${not empty marketPromotion.pmtId}">
			$('#coupon_status').attr('value','${marketCoupons.couponStatus}');			
			setCouponPromotion(${marketPromotion.pmtsId});
			//bug 
			$('#coupon_scheme_method_value').attr('value','${marketPromotion.pmtMethodValue}');	
		</c:if>
		
	function setCouponPromotion(obj){
		var scheme = $('#coupon_scheme_'+obj);
		scheme.attr("checked", true);
		var method = scheme.attr('method');		
		$('#coupon_scheme_method').attr('value',method);		
		$('#coupon_scheme_method_value').attr('value','');	
		if(method == 'coupon_discount'){
			$('#coupon_promotion_title').html('');
			$('#coupon_promotion_title').html('请输入给予多少折扣  ');
			$('#method_description').html('');
			$('#method_description').html('如果打9折，请输入0.9； ');
			$('#promotion_from_to').css('display','');
		}else if(method == 'coupon_less'){
			$('#coupon_promotion_title').html('');
			$('#coupon_promotion_title').html('请输入减多少金额  ');
			$('#method_description').html('');
			$('#promotion_from_to').css('display','');
		}else if(method == 'coupon_cash'){
			$('#coupon_promotion_title').html('');
			$('#coupon_promotion_title').html('请输入代金券/礼品卡的金额  ');
			$('#method_description').html('');
			$('#marketPromotion_orderMoneyFrom').val('0');
			
			$('#promotion_from_to').css('display','none');
		}
	
	}
	
		
		
	$(document).ready(function() {
		var validator = $("#coupon_form").validate( {
			errorElement : "div",
			errorClass : "x-vali-error",
			onfocusout : false,
			rules : {
 				'marketPromotion.orderMoneyFrom' : {
					required : true,
					number : true
				},
				'marketPromotion.orderMoneyTo' : {
					required : true,
					number : true
				},
				'marketPromotion.pmtsId' : "required",
				'marketPromotion.pmtTimeBeginString' : "required",
				'marketPromotion.pmtTimeEndString' : "required",
				 'marketPromotion.pmtMethodValue' : "required",
				'marketPromotion.pmtDescribe' : "required" 
			},
			messages : {
			
			
				'marketPromotion.orderMoneyFrom' : {
					required : "必填字段",
					number : "请输入数字"
				},
				'marketPromotion.orderMoneyTo' : {
					required : "必填字段",
					number : "请输入数字"
				},
				'marketPromotion.pmtsId' : "必填字段",
				'marketPromotion.pmtTimeBeginString' : "必填字段",
				'marketPromotion.pmtTimeEndString' : "必填字段",
				 'marketPromotion.pmtMethodValue' : "必填字段",
				'marketPromotion.pmtDescribe' : "必填字段"
				 
			},
			errorPlacement : function(error, element) {
				element.removeClass('x-vali-error');
				error.appendTo(element.parent());

			},
			 
			success : function(div) { 
				$(div).remove();
			}
		});
	});
	function checkLevel(){
		var selected = false;
		$('#promotion_level input[vname]').each(function(i, dom) {
			if ($(dom).attr("checked")) {
				selected = true;
			}
		});
		if(!selected){
			alert('请至少选择一个等级');
		}
		return selected;
	}
	
	$("#rule_start_time").datepicker( $.datepicker.regional['zh-CN']);
	$("#rule_end_time").datepicker( $.datepicker.regional['zh-CN']);
</script>
	</body>
</html>